Repository navigation
Close four places where this node judges a block differently from rskj - #408
Merged
Merged
Conversation
A consensus client that accepts a block the reference client rejects, or the reverse, puts the two on different chains. Four such places, each the same shape: a rule rskj runs that this node did not, or a verdict it gives that this node gave the other way. Each is checked against real mainnet history, because a rule stricter than the chain it has to accept is a fork and an argument cannot tell you which one you have written. **A header's version is now validated.** rskj's `BlockHeaderVersionRule` runs in both its block rule list and its snap rule list: 0 before RSKIP-351, 1 from it, 2 from RSKIP-535. This node computed the required version for *building* a header and nothing checked an incoming one, and nothing else rejected a mismatch either -- `header_version` had no caller outside the mining template and its tests. So a header declaring a version its height does not call for was accepted here and refused there. The rule mirrors rskj's, including the genesis exemption, and an unversioned header answers 0, as rskj's `BlockHeaderV0` does. Against the chain: 1,344 real mainnet headers, all version 0 as required, none rejected. That check is now a permanent case in `mainnet_block_rules`, which is also what catches it if RSKIP-351 is ever scheduled and the expectation has to become an activation height rather than a constant. It also found an unrealistic fixture. The uncle tests build headers on regtest, where RSKIP-351 is active from the start, so an unversioned fixture there is not a header the chain would carry. They now carry the version their height calls for, stamped before sealing because the merged-mining proof commits to the hash. **Genesis gets rskj's verdict.** `BlockValidatorImpl.isValid` refuses a genesis block outright; `validate_block_rules` returned `Ok(())` for height 0. Opposite answers to the same question, so any caller that branched on the result behaved oppositely on the two clients. It now returns `GenesisNotValidated`. The rules could not run on genesis either way -- it carries no REMASC transaction -- so refusing to answer is the honest verdict, and it is rskj's. Nothing depended on the old one. **The ommers hash is checked during validation, not only during execution.** rskj runs `BlockUnclesHashValidationRule` inside `BlockUnclesValidationRule`, so it is in the block rule list. Here it lived in `process_block_inner`, which agrees on every path that executes and differs on any that validates without -- snap and relay do exactly that. It is now in `validate_uncles` as well, which costs one keccak over a list of at most ten headers. That change found a live defect in the miner. `admissible_uncles` judges a candidate block with the real import rule, and its comment recorded the assumption the new check broke: "the rule reads the block's number, its parent's hash and its uncles, and nothing else of its header". The candidate inherited the *parent's* ommers hash, which is the hash of a different list, so every candidate would have failed and the miner would have dropped every uncle it was offered -- silently, with no uncle reward, and only a warning in the log. The candidate now claims the hash of the uncles it names, which is true of any real block. **The fork-detection view must be exactly 449.** rskj's `hasEnoughBlocksToCalculateForkDetectionData` refuses a view that is not exactly `requiredBlocks`; this refused only a short one and would have computed from the first 449 of a longer one. The two agree on every input that exists -- `validate` asks for exactly `REQUIRED_BLOCKS` and every `MainchainView` caps at `count` -- so this is a guard that stopped saying what it meant, and would have become a split through a change to the view builder, which is not a place anyone would look for one. The miner's `mining::fork_detection::calculate` keeps `<` deliberately: it takes the best chain uncapped and returns empty data for a chain too short, which is what rskj's `BlockToMineBuilder` does. Both sites now say which they are, so the next person does not "fix" the other one. Tightening it exposed two fixtures feeding the calculator a shape no caller produces -- one passing the whole chain and leaning on the first 449 being used. They now pass what the validator passes. Verified: core 378, execution 1,913, sync 670, cli 164, clippy clean, and all five `mainnet_block_rules` cases against this node's own block store. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Four places where this node judged a block differently from rskj. Each is checked against real mainnet history, because a rule stricter than the chain it must accept is a fork, and an argument cannot tell you which one you have written.
1. A header's version is now validated
rskj's
BlockHeaderVersionRuleruns in both the block rule list and the snap rule list — 0 before RSKIP-351, 1 from it, 2 from RSKIP-535. This node computed the required version for building a header and nothing checked an incoming one.I confirmed nothing else rejected a mismatch first:
header_versionhad no caller outside the mining template and its own tests. So a header declaring a version its height does not call for was accepted here and refused there.Against the chain: 1,344 real mainnet headers, all version 0 as required, none rejected. That is now a permanent case in
mainnet_block_rules, which also catches the day RSKIP-351 is scheduled and the expectation has to become an activation height rather than a constant.It also exposed an unrealistic fixture: the uncle tests build headers on regtest, where RSKIP-351 is active from the start, so an unversioned fixture there is not a header the chain would ever carry. They now carry the version their height calls for, stamped before sealing, since the merged-mining proof commits to the hash.
2. Genesis gets rskj's verdict
BlockValidatorImpl.isValidrefuses a genesis block outright.validate_block_rulesreturnedOk(())for height 0 — the opposite answer to the same question, so any caller branching on the result behaved oppositely on the two clients.Now
GenesisNotValidated. The rules cannot run on genesis either way (it carries no REMASC transaction), so refusing to answer is the honest verdict and it is rskj's. The execution suite confirms nothing depended on the old one.3. The ommers hash is checked during validation, not only during execution
rskj runs
BlockUnclesHashValidationRuleinsideBlockUnclesValidationRule, i.e. in the block rule list. Here it lived inprocess_block_inner, which agrees on every path that executes and differs on any that validates without — snap and relay do exactly that. It is now invalidate_unclestoo, costing one keccak over a list of at most ten headers.This change found a live defect in the miner.
admissible_unclesjudges a candidate block with the real import rule, and its comment recorded the assumption the new check broke:The candidate inherited the parent's
ommers_hash, which is the hash of a different list. Every candidate would have failed, and the miner would have dropped every uncle it was offered — silently, forfeiting the uncle rewards, with only a warning in the log. The candidate now claims the hash of the uncles it names, which is true of any real block.4. The fork-detection view must be exactly 449
rskj's
hasEnoughBlocksToCalculateForkDetectionDatarefuses a view that is not exactlyrequiredBlocks. This refused only a short one, and would have computed from the first 449 of a longer one.The two agree on every input that exists —
validateasks for exactlyREQUIRED_BLOCKS, and everyMainchainViewcaps atcount— so this was a guard that had stopped saying what it meant. It would have become a split through a change to the view builder, which is not a place anyone would look for one.The miner's
mining::fork_detection::calculatekeeps<deliberately: it takes the best chain uncapped and returns empty data for a chain too short, as rskj'sBlockToMineBuilderdoes. Both sites now say which they are, so the next person does not "fix" the other.Tightening it exposed two fixtures feeding the calculator a shape no caller produces — one passing the whole chain and relying on the first 449 being used. They now pass what the validator passes.
Verification
mainnet_block_rules(real chain)--workspace --all-targetsThe mainnet harness matters most here: it runs the new header-version rule and the uncle rules — including the ommers-hash check — over real blocks from this node's own store, which is the repository's standard for a consensus change.
🤖 Generated with Claude Code